/**
 * File name:     DirectEmailProcessor.java
 * Author:        Sapient Corporation
 * Creation date: Jun 07, 2007
 */
package com.kapil.framework.email;

import org.apache.commons.lang.exception.ExceptionUtils;

import com.kapil.framework.logger.ILogger;
import com.kapil.framework.logger.LogFactory;

/**
 * Processes an email in real time, i.e. sends it immediately.
 */
public final class DirectEmailDispatcher extends BaseEmailDispatcher
{
    private static final ILogger LOGGER = LogFactory.getInstance().getLogger(DirectEmailDispatcher.class);
    
    
    public DirectEmailDispatcher(EmailServer server)
    {
        super(server);
    }
    
    
    /**
     * Sends an email using an email host.
     * 
     * @param emailContent An {@link EmailVO} object containing information about the email to be sent.
     * @return boolean <code>true</code> if the email is sent successfully, <code>false</code> otherwise.
     */
    public boolean dispatchEmail(EmailVO emailContent)
    {
        boolean result = false;

        try
        {
            super.sendEmail(emailContent);
            result = true;
        }
        catch (Exception e)
        {
            // On Development environment, the processor is called with a non-existent email host name deliberately.  This is required to ensure
            // that a real email server isn't bombarded with multiple emails in a working day.  However, using a dummy email host name throws
            // exceptions.  The check below ensures that the log message isn't output on the Development environment, as it unnecessarily
            // confuses users.
            LOGGER.error("An error occurred while attempting to send an email message.  Details are provided below.");
            LOGGER.error(ExceptionUtils.getFullStackTrace(e));
        }

        return result;
    }
}
